<?php
/**
 * Created by PhpStorm.
 * User: zhaojunlike
 * Date: 2016/12/1
 * Time: 12:36
 */

namespace Home\Controller;


use Think\Controller;

class AuthController extends Controller
{
    protected $user_id;
    protected $user_phone;
    protected $user;

    protected function _initialize()
    {
        if (!$this->checkLogin()) {
            redirect(U('public/login'));
        } else {
            //
            $this->user_id = $this->checkLogin();
            $uMap['u_id'] = $this->user_id;
            $this->user = M('user')->where($uMap)->find();
            if (!$this->user) {
                redirect(U('public/login'));
                session('user_login_id', null);
                $this->error("用户已经被移除系统");
            }
            $this->assign('_user', $this->user);
        }
    }

    protected function checkLogin()
    {
        $id=session('user_login_id');
        if (!$id) {
            return session('user_login_id');
        } else {
            return false;
        }
    }

    //检测用户是否实名认证
    protected function checkUserRealAuth()
    {
        if ($this->user['real_status'] != 1) {
            $this->error("对不起,您必须实名认证以后才可以进入赛场", U('user/do_auth'));
            return false;
        } else {
            return true;
        }
    }
}